<!DOCTYPE html>
<html lang="zh-cn" dir="ltr">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Golang易错知识点 # GoMock # GoMock可以对interface打桩 GoMock可以对类成员函数打桩 GoMock可以对函数打桩 GoMock打桩后的依赖注入可以通过GoStub完成 GoStub # GoStub可以对全局变量打桩 GoStub可以对函数打桩 GoStub可以动态打桩，比如对一个函数打桩后，多次调用该函数会有不同的行为 作用域 # func main() { a := 12 { a := 13 _ = a // make compiler happy } fmt.Println(a) } 输出 12。 在作用域内的 a 在作用域外失效，所以输出 12。
添加方法 # 可以给任意类型添加相应的方法。这一说法是否正确 false
如果直接给int添加method会报错
任意自定义类型(包括内置类型，但不包括指针类型)添加相应的方法。
序列化 # type S struct { A int B *int C float64 d func() string e chan struct{} } func main() { s := S{ A: 1, B: nil, C: 12.">
<meta name="theme-color" content="#FFFFFF">
<meta name="color-scheme" content="light dark"><meta property="og:title" content="go语言基础（三）" />
<meta property="og:description" content="Golang易错知识点 # GoMock # GoMock可以对interface打桩 GoMock可以对类成员函数打桩 GoMock可以对函数打桩 GoMock打桩后的依赖注入可以通过GoStub完成 GoStub # GoStub可以对全局变量打桩 GoStub可以对函数打桩 GoStub可以动态打桩，比如对一个函数打桩后，多次调用该函数会有不同的行为 作用域 # func main() { a := 12 { a := 13 _ = a // make compiler happy } fmt.Println(a) } 输出 12。 在作用域内的 a 在作用域外失效，所以输出 12。
添加方法 # 可以给任意类型添加相应的方法。这一说法是否正确 false
如果直接给int添加method会报错
任意自定义类型(包括内置类型，但不包括指针类型)添加相应的方法。
序列化 # type S struct { A int B *int C float64 d func() string e chan struct{} } func main() { s := S{ A: 1, B: nil, C: 12." />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://example.org/docs/golang/%E5%9F%BA%E7%A1%80/go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B8%89/" /><meta property="article:section" content="docs" />
<meta property="article:published_time" content="2022-09-14T09:58:30+08:00" />
<meta property="article:modified_time" content="2022-09-14T09:58:30+08:00" />

<title>go语言基础（三） | Soulmate</title>
<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/book.min.c58292d36b18b675680ab9baea2029204537b839ea72f258746ec0f32ce8d6c8.css" integrity="sha256-xYKS02sYtnVoCrm66iApIEU3uDnqcvJYdG7A8yzo1sg=" crossorigin="anonymous">
  <script defer src="/flexsearch.min.js"></script>
  <script defer src="/en.search.min.7d4a2df4b0464655ec51cd667723b235b8c0102457ac51664365cdfb0a14ab66.js" integrity="sha256-fUot9LBGRlXsUc1mdyOyNbjAECRXrFFmQ2XN&#43;woUq2Y=" crossorigin="anonymous"></script>
<!--
Made with Book Theme
https://github.com/alex-shpak/hugo-book
-->
  
</head>
<body dir="ltr">
  <input type="checkbox" class="hidden toggle" id="menu-control" />
  <input type="checkbox" class="hidden toggle" id="toc-control" />
  <main class="container flex">
    <aside class="book-menu">
      <div class="book-menu-content">
        
  <nav>
<h2 class="book-brand">
  <a class="flex align-center" href="/"><img src="/logo.png" alt="Logo" /><span>Soulmate</span>
  </a>
</h2>


<div class="book-search">
  <input type="text" id="book-search-input" placeholder="Search" aria-label="Search" maxlength="64" data-hotkeys="s/" />
  <div class="book-search-spinner hidden"></div>
  <ul id="book-search-results"></ul>
</div>












  



  
  <ul>
    
      
        <li class="book-section-flat" >
          
  
  

  
    <input type="checkbox" id="section-074eed0fb8c6f9d99dfeff898388792f" class="toggle"  />
    <label for="section-074eed0fb8c6f9d99dfeff898388792f" class="flex justify-between">
      <a role="button" class="">计算机基础</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/git%E5%9F%BA%E7%A1%80/" class="">Git基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/linux%E5%9F%BA%E7%A1%80/" class="">Linux基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%9F%BA%E7%A1%80/" class="">操作系统基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9F%BA%E7%A1%80/" class="">数据库基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/" class="">计算机网络基础</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li class="book-section-flat" >
          
  
  

  
    <span>Golang</span>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-670eda717a06f31447c52422ec93a159" class="toggle" checked />
    <label for="section-670eda717a06f31447c52422ec93a159" class="flex justify-between">
      <a role="button" class="">基础</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B8%89/" class="active">go语言基础（三）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/2021-12-27-gin%E6%A1%86%E6%9E%B6/" class="">gin框架</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/beego%E6%A1%86%E6%9E%B6/" class="">Beego框架</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/go%E8%AF%AD%E8%A8%80%E5%BA%95%E5%B1%82%E5%9F%BA%E7%A1%80/" class="">go语言底层基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/2022-05-24-gorm%E6%80%BB%E7%BB%93/" class="">Gorm总结</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/2021-12-20-benchmark%E6%B5%8B%E8%AF%95/" class="">benchmark测试</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/2021-04-07-go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B8%80/" class="">2021 04 07 Go语言基础（一）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/2021-10-26-go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%BA%8C/" class="">2021 10 26 Go语言基础（二）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E5%9F%BA%E7%A1%80/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-go/" class="">数据结构 Go</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-c453881a62c640f6a4cceec99c02477e" class="toggle"  />
    <label for="section-c453881a62c640f6a4cceec99c02477e" class="flex justify-between">
      <a role="button" class="">高阶</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/%E9%AB%98%E9%98%B6/go%E8%AF%AD%E8%A8%80%E9%AB%98%E9%98%B6%E4%B8%80/" class="">Go语言高阶（一）</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-ee53da12118bfd3e9b35f3e9494ab55b" class="toggle"  />
    <label for="section-ee53da12118bfd3e9b35f3e9494ab55b" class="flex justify-between">
      <a role="button" class="">LeetCode</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/leetcode/2021-10-14-golang%E5%8A%9B%E6%89%A3%E5%88%B7%E9%A2%98%E4%B8%80/" class="">golang力扣刷题（一）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/leetcode/2021-11-04-golang%E5%8A%9B%E6%89%A3%E5%88%B7%E9%A2%98%E4%BA%8C/" class="">golang力扣刷题（二）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/leetcode/%E5%BF%85%E5%88%B7top101/" class="">必刷top101</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/golang/leetcode/2021-10-28-leetcode%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%93/" class="">LeetCode算法总结</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li class="book-section-flat" >
          
  
  

  
    <span>区块链</span>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-76bfb65f46ce25a0ff78d6cc4ad47773" class="toggle"  />
    <label for="section-76bfb65f46ce25a0ff78d6cc4ad47773" class="flex justify-between">
      <a role="button" class="">Fabric</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-05-08-fabric-sdk-go%E8%AF%A6%E8%A7%A3/" class="">fabric-sdk-go详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-1e3df3eda5cf08a9c7e8cc723288fefb" class="toggle"  />
    <label for="section-1e3df3eda5cf08a9c7e8cc723288fefb" class="flex justify-between">
      <a role="button" class="">环境测试</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-03-18-centos%E5%AE%89%E8%A3%85fabric1.2/" class="">centos安装fabric1.2</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-03-22-fabric%E7%BD%91%E7%BB%9C%E4%B8%AD%E7%9A%84%E6%8A%A5%E9%94%99%E4%BA%8C/" class="">2021 03 22 Fabric网络中的报错（二）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-03-24-fabric%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="">2021 03 24 Fabric环境搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-03-25-fabric-solo%E8%8A%82%E7%82%B9%E6%B5%8B%E8%AF%95/" class="">2021 03 25 Fabric Solo节点测试</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-03-25-fabric%E5%A4%9A%E6%9C%BA%E6%90%AD%E5%BB%BA/" class="">2021 03 25 Fabric多机搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-05-01-%E6%89%8B%E5%8A%A8%E7%94%9F%E6%88%90ca%E8%AF%81%E4%B9%A6%E6%90%AD%E5%BB%BAfabric%E7%BD%91%E7%BB%9C/" class="">2021 05 01 手动生成ca证书搭建fabric网络</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/2021-12-20-%E9%83%A8%E7%BD%B2tape%E6%B5%8B%E8%AF%95/" class="">2021 12 20 部署tape测试</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E7%8E%AF%E5%A2%83%E6%B5%8B%E8%AF%95/fabric%E7%BD%91%E7%BB%9C%E4%B8%AD%E7%9A%84%E6%8A%A5%E9%94%99%E4%B8%80/" class="">Fabric网络中的报错（一）</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-25aef1d59a561fcefcaecb043ef8afd2" class="toggle"  />
    <label for="section-25aef1d59a561fcefcaecb043ef8afd2" class="flex justify-between">
      <a role="button" class="">配置文件</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/2021-03-29-configtx-yaml%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" class="">2021 03 29 Configtx Yaml文件详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/2021-03-29-crypto-config-yaml%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" class="">2021 03 29 Crypto Config Yaml文件详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/2021-03-30-config-yaml%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" class="">2021 03 30 Config Yaml文件详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/2021-03-30-docker-compose-yaml%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" class="">2021 03 30 Docker Compose Yaml文件详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/2021-05-01-cryptogen%E7%94%9F%E6%88%90%E7%9A%84%E8%AF%81%E4%B9%A6%E8%AF%A6%E8%A7%A3/" class="">2021 05 01 Cryptogen生成的证书详解</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2022-04-14-%E5%8D%87%E7%BA%A7%E9%93%BE%E7%A0%81/" class="">升级链码</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-04-15-fabric-ca%E8%AF%A6%E8%A7%A3/" class="">2021 04 15 Fabric Ca详解</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-04-15-fabric1.4%E5%A4%9A%E9%80%9A%E9%81%93%E5%AE%9E%E9%AA%8C/" class="">2021 04 15 Fabric1.4多通道实验</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-04-17-%E5%A6%82%E4%BD%95%E5%9C%A8%E5%B7%B2%E6%9C%89%E7%BB%84%E7%BB%87%E4%B8%AD%E5%A2%9E%E5%8A%A0%E8%8A%82%E7%82%B9/" class="">2021 04 17 如何在已有组织中增加节点</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-05-02-fabric%E6%B5%8F%E8%A7%88%E5%99%A8%E6%90%AD%E5%BB%BA/" class="">2021 05 02 Fabric浏览器搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2021-05-10-%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6/" class="">2021 05 10 智能合约</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2022-02-25-fabric%E7%9B%B8%E5%85%B3%E6%9C%BA%E5%88%B6%E4%B8%8E%E5%8E%9F%E7%90%86/" class="">2022 02 25 Fabric相关机制与原理</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/fabric/2022-03-25-%E5%8C%BA%E5%9D%97%E9%93%BE%E7%BD%91%E7%BB%9C%E6%B7%BB%E5%8A%A0%E7%BB%84%E7%BB%87/" class="">2022 03 25 区块链网络添加组织</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-b07621083aa30b12de4c0333941e479f" class="toggle"  />
    <label for="section-b07621083aa30b12de4c0333941e479f" class="flex justify-between">
      <a role="button" class="">比特币</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E6%AF%94%E7%89%B9%E5%B8%81/2022-02-25-%E6%AF%94%E7%89%B9%E5%B8%81%E7%9B%B8%E5%85%B3%E6%9C%BA%E5%88%B6%E4%B8%8E%E5%8E%9F%E7%90%86/" class="">2022 02 25 比特币相关机制与原理</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-ff5477999ef29208270c84e8b56b2758" class="toggle"  />
    <label for="section-ff5477999ef29208270c84e8b56b2758" class="flex justify-between">
      <a role="button" class="">IPFS</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/ipfs/2021-06-02-ipfs%E7%A7%81%E6%9C%89%E7%BD%91%E7%BB%9C%E6%90%AD%E5%BB%BA/" class="">2021 06 02 IP Fs私有网络搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/ipfs/2021-07-08-ipfs%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E4%B8%80/" class="">2021 07 08 IP Fs基本原理（一）</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/ipfs/2021-07-12-ipfs-webui%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B7%A5%E5%85%B7%E6%90%AD%E5%BB%BA/" class="">2021 07 12 Ipfs Webui可视化工具搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/ipfs/2021-12-05-go-ipfs-api/" class="">2021 12 05 Go Ipfs API</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-77a0a17b06e8d04cfb0fba9952941706" class="toggle"  />
    <label for="section-77a0a17b06e8d04cfb0fba9952941706" class="flex justify-between">
      <a role="button" class="">密码学</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E5%AF%86%E7%A0%81%E5%AD%A6/2022-08-15-%E5%8C%BA%E5%9D%97%E9%93%BE%E5%AE%89%E5%85%A8%E5%9F%BA%E7%A1%80/" class="">区块链安全基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E5%AF%86%E7%A0%81%E5%AD%A6/2021-04-12-%E6%A4%AD%E5%9C%86%E6%9B%B2%E7%BA%BF%E5%8A%A0%E5%AF%86/" class="">椭圆曲线加密</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E5%AF%86%E7%A0%81%E5%AD%A6/2021-03-04-%E5%AF%86%E7%A0%81%E5%AD%A6%E5%9F%BA%E7%A1%80/" class="">密码学基础</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-2e4d10b323fd668021dbd532575d8790" class="toggle"  />
    <label for="section-2e4d10b323fd668021dbd532575d8790" class="flex justify-between">
      <a role="button" class="">Docker</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/docker/docker%E5%9F%BA%E7%A1%80/" class="">Docker基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/docker/dockerfile/" class="">Dockerfile</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/docker/2021-04-30-docker%E5%B8%B8%E7%94%A8%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/" class="">docker常用知识总结</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-70383d7f28a7ae4bf840a844eb61aa16" class="toggle"  />
    <label for="section-70383d7f28a7ae4bf840a844eb61aa16" class="flex justify-between">
      <a role="button" class="">共识算法</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E5%85%B1%E8%AF%86%E7%AE%97%E6%B3%95/2022-03-26-raft%E5%85%B1%E8%AF%86%E7%AE%97%E6%B3%95/" class="">Raft共识算法</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8C%BA%E5%9D%97%E9%93%BE/%E5%85%B1%E8%AF%86%E7%AE%97%E6%B3%95/%E5%85%B1%E8%AF%86%E7%AE%97%E6%B3%95%E5%9F%BA%E7%A1%80/" class="">共识算法基础</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li class="book-section-flat" >
          
  
  

  
    <span>数据库</span>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-94f26238d1ca3b5bcd40eadc7a88d726" class="toggle"  />
    <label for="section-94f26238d1ca3b5bcd40eadc7a88d726" class="flex justify-between">
      <a role="button" class="">MySql</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/2021-04-20-mysql%E5%9F%BA%E7%A1%80%E6%80%BB%E7%BB%93/" class="">MySql基础总结</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/mac%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E6%89%80%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/" class="">Mac连接数据库所遇到的问题</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li>
          
  
  

  
    <input type="checkbox" id="section-01e4ef5e6295826a1eab8f1a7114ec2c" class="toggle"  />
    <label for="section-01e4ef5e6295826a1eab8f1a7114ec2c" class="flex justify-between">
      <a role="button" class="">Redis</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/2022-03-21-redis%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA/" class="">Redis集群搭建</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/2022-03-20-redis%E5%9F%BA%E7%A1%80/" class="">Redis基础</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/2021-05-02-redis%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/" class="">redis面试总结</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
  </ul>

        </li>
      
    
      
        <li class="book-section-flat" >
          
  
  

  
    <input type="checkbox" id="section-5f7b667081fbae0581cd216f66d5102f" class="toggle"  />
    <label for="section-5f7b667081fbae0581cd216f66d5102f" class="flex justify-between">
      <a role="button" class="">博客</a>
    </label>
  

          
  <ul>
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8D%9A%E5%AE%A2/2022-08-27-%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BAhugo/" class="">个人博客搭建Hugo</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="/docs/%E5%8D%9A%E5%AE%A2/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BAhexo/" class="">个人博客搭建Hexo</a>
  

        </li>
      
    
  </ul>

        </li>
      
    
  </ul>











  
<ul>
  
  <li>
    <a href="https://gitee.com/chaincode" target="_blank" rel="noopener">
        Gitee
      </a>
  </li>
  
</ul>






</nav>




  <script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script>


 
      </div>
    </aside>

    <div class="book-page">
      <header class="book-header">
        
  <div class="flex align-center justify-between">
  <label for="menu-control">
    <img src="/svg/menu.svg" class="book-icon" alt="Menu" />
  </label>

  <strong>go语言基础（三）</strong>

  <label for="toc-control">
    
    <img src="/svg/toc.svg" class="book-icon" alt="Table of Contents" />
    
  </label>
</div>


  
  <aside class="hidden clearfix">
    
  
<nav id="TableOfContents">
  <ul>
    <li><a href="#golang易错知识点">Golang易错知识点</a>
      <ul>
        <li>
          <ul>
            <li><a href="#gomock">GoMock</a></li>
            <li><a href="#gostub">GoStub</a></li>
            <li><a href="#作用域">作用域</a></li>
            <li><a href="#添加方法">添加方法</a></li>
            <li><a href="#序列化">序列化</a></li>
            <li><a href="#指针">指针</a></li>
            <li><a href="#map">map</a></li>
            <li><a href="#switch">switch</a></li>
            <li><a href="#常量">常量</a></li>
            <li><a href="#变量">变量</a></li>
            <li><a href="#init函数">init函数</a></li>
            <li><a href="#json转换">JSON转换</a></li>
            <li><a href="#defer函数">defer函数</a></li>
            <li><a href="#值类型">值类型</a></li>
            <li><a href="#返回值">返回值</a></li>
            <li><a href="#取反操作">取反操作</a></li>
            <li><a href="#import">import</a></li>
            <li><a href="#字符串">字符串</a></li>
            <li><a href="#int">int</a></li>
            <li><a href="#delete函数">delete函数</a></li>
            <li><a href="#panic">Panic</a></li>
            <li><a href="#死锁">死锁</a></li>
            <li><a href="#main函数">main函数</a></li>
            <li><a href="#goconvey">goconvey</a></li>
            <li><a href="#select">select</a></li>
            <li><a href="#go-vendor">go Vendor</a></li>
            <li><a href="#channel">channel</a></li>
            <li><a href="#切片">切片</a></li>
            <li><a href="#内存泄漏">内存泄漏</a></li>
            <li><a href="#匿名函数">匿名函数</a></li>
            <li><a href="#cgo">Cgo</a></li>
            <li><a href="#关键字">关键字</a></li>
            <li><a href="#同步锁">同步锁</a></li>
            <li><a href="#cap">cap</a></li>
            <li><a href="#接口">接口</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>



  </aside>
  
 
      </header>

      
      
  <article class="markdown"><h1 id="golang易错知识点">
  Golang易错知识点
  <a class="anchor" href="#golang%e6%98%93%e9%94%99%e7%9f%a5%e8%af%86%e7%82%b9">#</a>
</h1>
<h3 id="gomock">
  GoMock
  <a class="anchor" href="#gomock">#</a>
</h3>
<ul>
<li>GoMock可以对interface打桩</li>
<li>GoMock可以对类成员函数打桩</li>
<li>GoMock可以对函数打桩</li>
<li>GoMock打桩后的依赖注入可以通过GoStub完成</li>
</ul>
<h3 id="gostub">
  GoStub
  <a class="anchor" href="#gostub">#</a>
</h3>
<ul>
<li>GoStub可以对全局变量打桩</li>
<li>GoStub可以对函数打桩</li>
<li>GoStub可以动态打桩，比如对一个函数打桩后，多次调用该函数会有不同的行为</li>
</ul>
<h3 id="作用域">
  作用域
  <a class="anchor" href="#%e4%bd%9c%e7%94%a8%e5%9f%9f">#</a>
</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">a</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">12</span>
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">a</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">13</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">_</span> = <span style="color:#a6e22e">a</span> <span style="color:#75715e">// make compiler happy
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#a6e22e">a</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">输出</span> <span style="color:#ae81ff">12</span><span style="color:#960050;background-color:#1e0010">。</span>
</span></span></code></pre></div><p>在作用域内的 a 在作用域外失效，所以输出 12。</p>
<h3 id="添加方法">
  添加方法
  <a class="anchor" href="#%e6%b7%bb%e5%8a%a0%e6%96%b9%e6%b3%95">#</a>
</h3>
<p>可以给任意类型添加相应的方法。这一说法是否正确        <font color='red'>false</font></p>
<blockquote>
<p>如果直接给int添加method会报错</p>
<p>任意自定义类型(包括内置类型，但不包括指针类型)添加相应的方法。</p>
</blockquote>
<h3 id="序列化">
  序列化
  <a class="anchor" href="#%e5%ba%8f%e5%88%97%e5%8c%96">#</a>
</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">type</span> <span style="color:#a6e22e">S</span> <span style="color:#66d9ef">struct</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">A</span> <span style="color:#66d9ef">int</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">B</span> <span style="color:#f92672">*</span><span style="color:#66d9ef">int</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">C</span> <span style="color:#66d9ef">float64</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">d</span> <span style="color:#66d9ef">func</span>() <span style="color:#66d9ef">string</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">e</span> <span style="color:#66d9ef">chan</span> <span style="color:#66d9ef">struct</span>{}
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">s</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">S</span>{
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">A</span>: <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">B</span>: <span style="color:#66d9ef">nil</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">C</span>: <span style="color:#ae81ff">12.15</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">d</span>: <span style="color:#66d9ef">func</span>() <span style="color:#66d9ef">string</span> {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;NowCoder&#34;</span>
</span></span><span style="display:flex;"><span>        },
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">e</span>: make(<span style="color:#66d9ef">chan</span> <span style="color:#66d9ef">struct</span>{}),
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">_</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">json</span>.<span style="color:#a6e22e">Marshal</span>(<span style="color:#a6e22e">s</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">log</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;err occurred..&#34;</span>)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">log</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;everything is ok.&#34;</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">没有发生错误</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">输出</span> <span style="color:#a6e22e">everything</span> <span style="color:#a6e22e">is</span> <span style="color:#a6e22e">ok</span>
</span></span></code></pre></div><pre tabindex="0"><code>尽管标准库在遇到管道/函数等无法被序列化的内容时会发生错误，但因为本题中 d 和 e 均为小写未导出变量，因此不会发生序列化错误。
</code></pre><h3 id="指针">
  指针
  <a class="anchor" href="#%e6%8c%87%e9%92%88">#</a>
</h3>
<p>通过指针变量 p 访问其成员变量 name</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">p</span>.<span style="color:#a6e22e">name</span>
</span></span><span style="display:flex;"><span>(<span style="color:#f92672">*</span><span style="color:#a6e22e">p</span>).<span style="color:#a6e22e">name</span>
</span></span><span style="display:flex;"><span>(<span style="color:#f92672">&amp;</span><span style="color:#a6e22e">p</span>).<span style="color:#a6e22e">name</span>    <span style="color:#75715e">//false
</span></span></span></code></pre></div><pre tabindex="0"><code>“*”是根据指针地址去找地址指向的内存中存储的具体值，“&amp;”是根据内存中存储的具体值去反查对应的内存地址。题目中已经说明了p是指针，也就是内存地址，要使用变量(这里是调用成员属性)，当然是要先根据内存地址获取存储的具体内容，选*p。
</code></pre><hr>
<p>golang中没有隐藏的this指针，这句话的含义是:</p>
<ul>
<li>方法施加的对象显示传递，没有被隐藏起来</li>
<li>golang的面向对象表达更直观，对于面向过程只是换了一种语法形式来表达</li>
<li>方法施加的对象不需要非得是指针，也不用非得this</li>
</ul>
<hr>
<p>go语言中的指针不支持运算。</p>
<h3 id="map">
  map
  <a class="anchor" href="#map">#</a>
</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">var</span> <span style="color:#a6e22e">m</span> <span style="color:#66d9ef">map</span>[<span style="color:#66d9ef">string</span>]<span style="color:#66d9ef">int</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">m</span>[<span style="color:#e6db74">&#34;one&#34;</span>]=<span style="color:#ae81ff">1</span>     <span style="color:#75715e">//false
</span></span></span></code></pre></div><p>Make只用来创建slice,map,channel。 其中map使用前必须初始化。 append可直接动态扩容slice，而map不行。</p>
<h3 id="switch">
  switch
  <a class="anchor" href="#switch">#</a>
</h3>
<p>switch后面可以不跟表达式。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">switch</span>{
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">case</span> <span style="color:#ae81ff">0</span><span style="color:#f92672">&lt;=</span><span style="color:#a6e22e">Num</span><span style="color:#f92672">&amp;&amp;</span><span style="color:#a6e22e">Num</span><span style="color:#f92672">&lt;=</span><span style="color:#ae81ff">3</span>:
</span></span><span style="display:flex;"><span>		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;0-3&#34;</span>)
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">case</span> <span style="color:#ae81ff">4</span><span style="color:#f92672">&lt;=</span><span style="color:#a6e22e">Num</span><span style="color:#f92672">&amp;&amp;</span><span style="color:#a6e22e">Num</span><span style="color:#f92672">&lt;=</span><span style="color:#ae81ff">6</span>:
</span></span><span style="display:flex;"><span>		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;4-6&#34;</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">与其他语言不同</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">go语言支持不需要表达式的写法</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">效果等同if</span> <span style="color:#66d9ef">else</span>
</span></span></code></pre></div><hr>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">s</span> <span style="color:#f92672">:=</span> <span style="color:#e6db74">&#34;nowcoder&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">a</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">switch</span> <span style="color:#a6e22e">s</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">case</span> <span style="color:#e6db74">&#34;nowcoder&#34;</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">a</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">fallthrough</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">case</span> <span style="color:#e6db74">&#34;haha&#34;</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">a</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">fallthrough</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">default</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">a</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#a6e22e">a</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">输出3</span>
</span></span></code></pre></div><pre tabindex="0"><code>fallthrough会强制执行后面的case代码，不管后面的case是不是true
</code></pre><h3 id="常量">
  常量
  <a class="anchor" href="#%e5%b8%b8%e9%87%8f">#</a>
</h3>
<p>对于常量定义zero(const zero = 0.0)，zero是浮点型常量，这一说法是否正确。   <font color='red'>false</font></p>
<blockquote>
<p>Go语言的常量有个不同寻常之处。虽然一个常量可以有任意有一个确定的基础类型，例如int或float64，或者是类似time.Duration这样命名的基础类型，但是<strong>许多常量并没有一个明确的基础类型</strong>。编译器为这些没有明确的基础类型的数字常量提供比基础类型更高精度的算术运算；你可以认为至少有256bit的运算精度。这里有六种未明确类型的常量类型，分别是无类型的布尔型、无类型的整数、无类型的字符、无类型的浮点数、无类型的复数、无类型的字符串。</p>
</blockquote>
<hr>
<p>go语言中的++、&ndash;操作符都是后置操作符，必须跟在操作数后面，并且它们没有返回值，所以它们不能用于表达式。</p>
<hr>
<p><strong>go语言常量要是编译时就能确定的数据</strong></p>
<hr>
<h3 id="变量">
  变量
  <a class="anchor" href="#%e5%8f%98%e9%87%8f">#</a>
</h3>
<h4 id="匿名变量">
  匿名变量
  <a class="anchor" href="#%e5%8c%bf%e5%90%8d%e5%8f%98%e9%87%8f">#</a>
</h4>
<p>如果调用方调用了一个具有多返回值的方法，但是却不想关心其中的某个返回值，可以简单的用一个下划线“_&ldquo;来跳过这个返回值，该下划线对应的变量叫匿名变量</p>
<h3 id="init函数">
  init函数
  <a class="anchor" href="#init%e5%87%bd%e6%95%b0">#</a>
</h3>
<ul>
<li>一个包中，可以包含多个init函数</li>
<li>程序运行时，先执行导入包的init函数，再执行本包内的init函数</li>
<li>main函数只能在main包中有且仅有一个，main包中可以有一个或多个init函数</li>
<li>init函数和main函数都不能被显示调用</li>
</ul>
<h3 id="json转换">
  JSON转换
  <a class="anchor" href="#json%e8%bd%ac%e6%8d%a2">#</a>
</h3>
<p>golang中大多数数据类型都可以转化为有效的JSON文本，除了channel、complex、函数等。</p>
<p>在golang指针中可进行隐式转换，对指针取值，对所指对象进行序列化。</p>
<h3 id="defer函数">
  defer函数
  <a class="anchor" href="#defer%e5%87%bd%e6%95%b0">#</a>
</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ch</span> <span style="color:#f92672">:=</span> make(<span style="color:#66d9ef">chan</span> <span style="color:#66d9ef">struct</span>{})
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">defer</span> close(<span style="color:#a6e22e">ch</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">go</span> <span style="color:#66d9ef">func</span>() {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">defer</span> close(<span style="color:#a6e22e">ch</span>)
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">ch</span> <span style="color:#f92672">&lt;-</span> <span style="color:#66d9ef">struct</span>{}{}
</span></span><span style="display:flex;"><span>    }()
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">i</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> <span style="color:#66d9ef">range</span> <span style="color:#a6e22e">ch</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;%d&#34;</span>, <span style="color:#a6e22e">i</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">输出</span><span style="color:#960050;background-color:#1e0010">：</span><span style="color:#a6e22e">panic</span>
</span></span></code></pre></div><p>重复关闭一个管道，会导致 panic</p>
<hr>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">file</span>,<span style="color:#a6e22e">err</span><span style="color:#f92672">:=</span><span style="color:#a6e22e">os</span>.<span style="color:#a6e22e">Open</span>(<span style="color:#e6db74">&#34;test.go&#34;</span>)
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">defer</span> <span style="color:#a6e22e">file</span>.<span style="color:#a6e22e">Close</span>()
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span><span style="color:#f92672">!=</span><span style="color:#66d9ef">nil</span>{
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;open file failed&#34;</span>,<span style="color:#a6e22e">err</span>)
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#f92672">...</span>
</span></span></code></pre></div><p>defer 应该放在err后，如果文件为空，close会崩溃</p>
<h3 id="值类型">
  值类型
  <a class="anchor" href="#%e5%80%bc%e7%b1%bb%e5%9e%8b">#</a>
</h3>
<p>数组是一个值类型,这一说法是否正确</p>
<p><img src="https://blockchaincode.oss-cn-hangzhou.aliyuncs.com/202209141116316.png" alt="" /></p>
<hr>
<pre tabindex="0"><code>var x string = nil    //错误
</code></pre><p>Go语言中的引用类型只有五个：</p>
<p><strong>切片</strong>  <strong>映射</strong>  <strong>函数</strong>  <strong>方法</strong>  <strong>通道</strong></p>
<p>nil只能赋值给上面五种通道类型的变量以及指针变量。</p>
<hr>
<h3 id="返回值">
  返回值
  <a class="anchor" href="#%e8%bf%94%e5%9b%9e%e5%80%bc">#</a>
</h3>
<p>在函数的多返回值中，如果有error或bool类型，则一般放在最后一个。</p>
<h3 id="取反操作">
  取反操作
  <a class="anchor" href="#%e5%8f%96%e5%8f%8d%e6%93%8d%e4%bd%9c">#</a>
</h3>
<p>对变量x的取反操作是~x，这一说法是否正确。   <font color='red'>false</font></p>
<blockquote>
<p>^x   // Go语言取反方式和C语言不同，Go语言不支持~符号</p>
</blockquote>
<h3 id="import">
  import
  <a class="anchor" href="#import">#</a>
</h3>
<ol>
<li><font color='red'>import后面跟的是包的路径，而不是包名； </font></li>
<li>同一个目录下可以有多个.go文件，但是只能有一个包；</li>
<li>使用第三方库时，先将源码编译成.a文件放到临时目录下，然后去链接这个.a文件，而不是go install安装的那个.a文件；</li>
<li>使用标准库时，直接链接.a文件，即使修改了源码，也不会从新编译源码；</li>
<li>不管使用的是标准库还是第三方库，源码都是必须存在的，即使使用的是.a文件。</li>
</ol>
<h3 id="字符串">
  字符串
  <a class="anchor" href="#%e5%ad%97%e7%ac%a6%e4%b8%b2">#</a>
</h3>
<p>字符串不支持下标操作</p>
<h3 id="int">
  int
  <a class="anchor" href="#int">#</a>
</h3>
<p>int 和 uint 的取值范围与体系架构有关，在 32 位机中等价于 int32 和 uint32，在 64 位机中等价于 int64 和 uint64。</p>
<hr>
<pre tabindex="0"><code>var i int=10
var i=10
i:=10
都正确
</code></pre><hr>
<h3 id="delete函数">
  delete函数
  <a class="anchor" href="#delete%e5%87%bd%e6%95%b0">#</a>
</h3>
<p>内置函数 delete 只能删除 map，参见源码：</p>
<pre tabindex="0"><code>func delete(m map[Type]Type1, key Type)
</code></pre><p>go数组是不可变类型，切片的删除没有指定的内置函数，也不能直接删除，都是通过切片的拼接进行的，s=append(s[i:]，s[:i+1])</p>
<h3 id="panic">
  Panic
  <a class="anchor" href="#panic">#</a>
</h3>
<p>当内置的panic()函数调用时，外围函数或方法的执行会立即终止。然后，任何延迟执行(defer)的函数或方法都会被调用，就像其外围函数正常返回一样。最后，调用返回到该外围函数的调用者，就像该外围调用函数或方法调用了panic()一样，因此该过程一直在调用栈中重复发生：函数停止执行，调用延迟执行函数等。当到达main()函数时不再有可以返回的调用者，因此这个过程会终止，并将包含传入原始panic()函数中的值的调用栈信息输出到os.Stderr。</p>
<hr>
<p>关于异常的触发，下面说法正确的是：</p>
<ul>
<li>空指针解析</li>
<li>下标越界</li>
<li>除数为0</li>
<li>调用panic函数</li>
</ul>
<hr>
<p>函数执行时，如果由于Panic导致了异常，程序停止执行，然后调用延迟函数defer，就像程序正常退出一样。另外recover也是要写在延迟函数中的，如果发生异常延迟函数就不执行了，那就永远无法recover了。</p>
<p>异常发生后，panic之前的defer函数会被执行，但是panic之后的defer函数并不会被执行。</p>
<hr>
<p>错误是业务过程的一部分，而异常不是。</p>
<h3 id="死锁">
  死锁
  <a class="anchor" href="#%e6%ad%bb%e9%94%81">#</a>
</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">wg</span> <span style="color:#a6e22e">sync</span>.<span style="color:#a6e22e">WaitGroup</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ans</span> <span style="color:#f92672">:=</span> int64(<span style="color:#ae81ff">0</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> <span style="color:#a6e22e">i</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">0</span>; <span style="color:#a6e22e">i</span> &lt; <span style="color:#ae81ff">3</span>; <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">wg</span>.<span style="color:#a6e22e">Add</span>(<span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">go</span> <span style="color:#a6e22e">newGoRoutine</span>(<span style="color:#a6e22e">wg</span>, <span style="color:#f92672">&amp;</span><span style="color:#a6e22e">ans</span>)
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">wg</span>.<span style="color:#a6e22e">Wait</span>()
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">newGoRoutine</span>(<span style="color:#a6e22e">wg</span> <span style="color:#a6e22e">sync</span>.<span style="color:#a6e22e">WaitGroup</span>, <span style="color:#a6e22e">i</span> <span style="color:#f92672">*</span><span style="color:#66d9ef">int64</span>) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">defer</span> <span style="color:#a6e22e">wg</span>.<span style="color:#a6e22e">Done</span>()
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">atomic</span>.<span style="color:#a6e22e">AddInt64</span>(<span style="color:#a6e22e">i</span>, <span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">发生死锁</span>
</span></span></code></pre></div><p>sync.Waitgroup 里面有 noCopy 结构，不应该使用值拷贝，只能使用指针传递。</p>
<p>go结构体传参是传值，不是传引用，newGoroutine函数里的第一个参数接收的sync.waitgroup是复制值，而不是main里定义的对象，改成*sync.Waitgroup即可</p>
<hr>
<h3 id="main函数">
  main函数
  <a class="anchor" href="#main%e5%87%bd%e6%95%b0">#</a>
</h3>
<pre tabindex="0"><code>main函数中可以使用flag包来获取和解析命令行参数
</code></pre><h3 id="goconvey">
  goconvey
  <a class="anchor" href="#goconvey">#</a>
</h3>
<ul>
<li>goconvey是一个支持golang的单元测试框架</li>
<li>goconvey能够自动监控文件修改并启动测试，并可以将测试结果实时输出到web页面</li>
<li>goconvey提供了丰富的断言简化测试用例的编写</li>
<li>goconvey无法与go test集成</li>
</ul>
<h3 id="select">
  select
  <a class="anchor" href="#select">#</a>
</h3>
<ul>
<li>select机制用来处理异步IO问题</li>
<li>select机制最大的一条限制就是每个case语句里必须是一个IO操作</li>
<li>golang在语言级别支持select关键字</li>
</ul>
<h3 id="go-vendor">
  go Vendor
  <a class="anchor" href="#go-vendor">#</a>
</h3>
<p>关于go vendor，下面说法正确的是：</p>
<ul>
<li>基本思路是将引用的外部包的源码放在当前工程的vendor目录下面</li>
<li>编译go代码会优先从vendor目录先寻找依赖包</li>
<li>有了vendor目录后，打包当前的工程代码到其他机器的$GOPATH/src下面都可以通过编译</li>
<li>go vendor无法精确的引用外部包进行版本控制，不能指定引用某个特定版本的外部包；只是在开发时，将其拷贝过来，但是一旦外部包升级,vendor下的代码不会跟着升级，</li>
</ul>
<h3 id="channel">
  channel
  <a class="anchor" href="#channel">#</a>
</h3>
<p>关于channel的特性，下面说法正确的是：</p>
<ul>
<li>给一个nil channel发送数据，造成永远阻塞</li>
<li>从一个nil channel接收数据，造成永远阻塞</li>
<li>给一个已经关闭的channel发送数据，引起Panic</li>
<li>从一个已经关闭的channel接收数据，如果缓冲区为空，则返回一个零值</li>
</ul>
<hr>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() { 
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ch</span> <span style="color:#f92672">:=</span> make(<span style="color:#66d9ef">chan</span> <span style="color:#66d9ef">struct</span>{}) 
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">go</span> <span style="color:#66d9ef">func</span>() {
</span></span><span style="display:flex;"><span>        close(<span style="color:#a6e22e">ch</span>)
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">ch</span> <span style="color:#f92672">&lt;-</span> <span style="color:#66d9ef">struct</span>{}{}
</span></span><span style="display:flex;"><span>    }() 
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">i</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> <span style="color:#66d9ef">range</span> <span style="color:#a6e22e">ch</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;%d&#34;</span>, <span style="color:#a6e22e">i</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">panic</span>
</span></span></code></pre></div><p>向关闭的管道发送请求会导致 panic</p>
<hr>
<p>无缓冲的channel是同步的，而有缓冲的channel是非同步的。</p>
<hr>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() { 
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ch</span> <span style="color:#f92672">:=</span> make(<span style="color:#66d9ef">chan</span> <span style="color:#66d9ef">struct</span>{})
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">defer</span> close(<span style="color:#a6e22e">ch</span>) 
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">go</span> <span style="color:#66d9ef">func</span>() {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">ch</span> <span style="color:#f92672">&lt;-</span> <span style="color:#66d9ef">struct</span>{}{}
</span></span><span style="display:flex;"><span>    }() 
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">i</span> <span style="color:#f92672">:=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> <span style="color:#66d9ef">range</span> <span style="color:#a6e22e">ch</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span>
</span></span><span style="display:flex;"><span>    } 
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Printf</span>(<span style="color:#e6db74">&#34;%d&#34;</span>, <span style="color:#a6e22e">i</span>)
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">死锁</span>
</span></span></code></pre></div><p>考察 channel 与 for-range 一起使用时容易发生死锁的情况，这里因为 ch 没有被关闭的时机，导致死锁。</p>
<p>for range 就是一直取，goroutine只发了一次，所以循环只转了一下就卡在接受了</p>
<h3 id="切片">
  切片
  <a class="anchor" href="#%e5%88%87%e7%89%87">#</a>
</h3>
<pre tabindex="0"><code>s := make([]int)    //错误
</code></pre><p>在对切片初始化的时候，make中的长度参数是必须的，容量是可以不用添加的</p>
<h3 id="内存泄漏">
  内存泄漏
  <a class="anchor" href="#%e5%86%85%e5%ad%98%e6%b3%84%e6%bc%8f">#</a>
</h3>
<p>关于内存泄漏，下面说法正确的是：</p>
<ul>
<li>
<p>golang中检测内存泄漏主要依靠的是pprof包</p>
</li>
<li>
<p>应定期使用浏览器来查看系统的实时内存信息，及时发现内存泄漏问题</p>
</li>
<li>
<p>内存泄漏不能在编译阶段发现</p>
</li>
</ul>
<h3 id="匿名函数">
  匿名函数
  <a class="anchor" href="#%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0">#</a>
</h3>
<p>匿名函数可以直接赋值给一个变量或者直接执行</p>
<h3 id="cgo">
  Cgo
  <a class="anchor" href="#cgo">#</a>
</h3>
<p>Golang可以复用C的模块，这个功能叫Cgo,CGO是C语言和Go语言之间的桥梁，原则上无法直接支持C++的类。CGO不支持C++语法的根本原因是C++至今为止还没有一个二进制接口规范(ABI)。</p>
<h3 id="关键字">
  关键字
  <a class="anchor" href="#%e5%85%b3%e9%94%ae%e5%ad%97">#</a>
</h3>
<blockquote>
<p>go关键字：</p>
<p>var和const ：变量和常量的声明</p>
<p>var varName type  或者 varName : = value
package and import: 导入
func： 用于定义函数和方法
return ：用于从函数返回
defer someCode ：在函数退出之前执行
go : 用于并行
select 用于选择不同类型的通讯
interface 用于定义接口
struct 用于定义抽象数据类型
break、case、continue、for、fallthrough、else、if、switch、goto、default 流程控制
chan用于channel通讯
type用于声明自定义类型
map用于声明map类型数据
range用于读取slice、map、channel数据</p>
</blockquote>
<h3 id="同步锁">
  同步锁
  <a class="anchor" href="#%e5%90%8c%e6%ad%a5%e9%94%81">#</a>
</h3>
<p>关于同步锁，下面说法正确的是：</p>
<p>当一个goroutine获得Mutex后，其他goroutine就只能乖乖的等待，除非该goroutine释放这个Mutex.</p>
<p>RWMutex在读锁占用的情况下，会阻止写，但不阻止读。</p>
<p>RWMutex在写占用情况下，会阻止任何其他goroutine（无论读和写）进来，整个锁相当于由该goroutine独占</p>
<p>一个goroutine持有写锁 Lock()，其他goroutine不能读、不能写；</p>
<p>一个goroutine持有读锁RLock()，其他goroutine 可读、不能写。</p>
<p>每一个Lock()都应该对应一个 UnLock()</p>
<p>无论是RWMutex还是Mutex，与Lock()对应的都是Unlock()</p>
<h3 id="cap">
  cap
  <a class="anchor" href="#cap">#</a>
</h3>
<p>cap的作用  不支持map</p>
<p>arry：返回数组的元素个数</p>
<p>slice：返回slice的最大容量</p>
<p>channel：返回channel的buffer容量</p>
<h3 id="接口">
  接口
  <a class="anchor" href="#%e6%8e%a5%e5%8f%a3">#</a>
</h3>
<p>关于接口，下面说法正确的是：</p>
<ul>
<li>
<p>只要两个接口拥有相同的方法列表（次序不同不要紧），那么他们就是等价的，可以相互赋值。</p>
</li>
<li>
<p>如果接口A的方法列表是接口B的方法列表的子集，那么接口B可以赋值给接口A。</p>
</li>
<li>
<p>接口查询是否成功，要在运行期才能够确定。</p>
</li>
<li>
<p>接口赋值是否可行在编译阶段就可以知道</p>
</li>
</ul>
</article>
 
      

      <footer class="book-footer">
        
  <div class="flex flex-wrap justify-between">





</div>



  <script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script>


 
        
      </footer>

      
  
  <div class="book-comments">

</div>
  
 

      <label for="menu-control" class="hidden book-menu-overlay"></label>
    </div>

    
    <aside class="book-toc">
      <div class="book-toc-content">
        
  
<nav id="TableOfContents">
  <ul>
    <li><a href="#golang易错知识点">Golang易错知识点</a>
      <ul>
        <li>
          <ul>
            <li><a href="#gomock">GoMock</a></li>
            <li><a href="#gostub">GoStub</a></li>
            <li><a href="#作用域">作用域</a></li>
            <li><a href="#添加方法">添加方法</a></li>
            <li><a href="#序列化">序列化</a></li>
            <li><a href="#指针">指针</a></li>
            <li><a href="#map">map</a></li>
            <li><a href="#switch">switch</a></li>
            <li><a href="#常量">常量</a></li>
            <li><a href="#变量">变量</a></li>
            <li><a href="#init函数">init函数</a></li>
            <li><a href="#json转换">JSON转换</a></li>
            <li><a href="#defer函数">defer函数</a></li>
            <li><a href="#值类型">值类型</a></li>
            <li><a href="#返回值">返回值</a></li>
            <li><a href="#取反操作">取反操作</a></li>
            <li><a href="#import">import</a></li>
            <li><a href="#字符串">字符串</a></li>
            <li><a href="#int">int</a></li>
            <li><a href="#delete函数">delete函数</a></li>
            <li><a href="#panic">Panic</a></li>
            <li><a href="#死锁">死锁</a></li>
            <li><a href="#main函数">main函数</a></li>
            <li><a href="#goconvey">goconvey</a></li>
            <li><a href="#select">select</a></li>
            <li><a href="#go-vendor">go Vendor</a></li>
            <li><a href="#channel">channel</a></li>
            <li><a href="#切片">切片</a></li>
            <li><a href="#内存泄漏">内存泄漏</a></li>
            <li><a href="#匿名函数">匿名函数</a></li>
            <li><a href="#cgo">Cgo</a></li>
            <li><a href="#关键字">关键字</a></li>
            <li><a href="#同步锁">同步锁</a></li>
            <li><a href="#cap">cap</a></li>
            <li><a href="#接口">接口</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>


 
      </div>
    </aside>
    
  </main>

  
</body>
</html>












